<?php
namespace Mobile\Controller;
use Think\Controller;
class ProductsController extends BaseController{
	public function index(){
		$flag = I('flag');
		$menu = M('Category') -> where(array('parent_id' => 3)) -> order('order_id desc,id asc') -> select();
		if($flag == ''){
			$categoryInfo = SearchOne('Category','flag',$THINK.CONTROLLER_NAME);
			$categoryInfo = SearchOne('Category','parent_id',$categoryInfo['id']);
			$flag = $categoryInfo['flag'];
		}else{
			$categoryInfo = SearchOne('Category','flag',$flag);
		}
		$category_id = $categoryInfo['id'];
		$list	= M('Products') -> where(array('category_id' => $category_id)) -> order('is_index desc,add_time desc,id asc') -> select();
		$view	= $list[0];
		if(!$_SERVER['HTTP_X_PJAX'] && IS_AJAX){
			$id = I('id');
			$view	= SearchOne('Products','id',$id);
			if($view){
				$date['thumb']			= $view['thumb'];
				$date['description']	= $view['description'];
				$date['details']		= $view['image'];
				$date['url']			= $view['url'];
				$date['status']	= '1';
				$this -> ajaxReturn($date);
			} else {
				$date['msg']	= '参数错误！';
				$date['status']	= '0';
				$this -> ajaxReturn($date);
			}
		}
		$this		-> assign('category_id',$category_id);
		$this		-> assign('categoryInfo',$categoryInfo);
		$this		-> assign('list',$list);
		$this		-> assign('view',$view);
		$this		-> assign('menu',$menu);
		$this		-> assign('flag',$flag);
		$this		-> display('products');
	}
}
